<?php include('header.php'); ?>
<aside id="side-nav" class="span3">
<?php include('side.php'); ?>
</aside>
<div class="span9 content-container">
	<div id="content-window" class="content">
		<h3>Available Sessions</h3>
<?php
	$userId = $_SESSION['userId'];

	error_reporting(0);
	$regShopMsg = $_GET['regShopMsg'];
	
	$con = mysql_connect("localhost", "group5", "group5");//change this when moving to/from wamp
    if(!$con)
    {
		echo "Connection failed!";
        exit;
    }
	
	mysql_select_db("group5");//change this when moving to/from wamp
	
	$shopQuery = mysql_query("select * from WORKSHOP as WS, WORKSHOP_SESSIONS as WSS where WS.workshopId = WSS.workshopId", $con);?>
	<p id='regShopMsg'><?php echo $regShopMsg; ?></p>
	<form name='regShopForm' action='registerShop.php' method='post'>
	<table id='allShops' class="table table-condensed table-striped table-bordered" name='allShops'>
		<tbody>
			<tr>
				<th>Select</th>
				<th>Workshop Title</th>
				<th>Meeting Date</th>
				<th>Meeting Time</th>
				<th>Workshop Description</th>
				<th>Instructor</th>
				<th>Building</th>
				<th>Room</th>
				<th>Capacity</th>
				<th>Current Enrolled</th>
			</tr>
	<?php
	while($newRow = mysql_fetch_row($shopQuery))
	{
		$workshopId =  $newRow[0];
		$title =  $newRow[1];
		$description =  $newRow[2];
		$category =  $newRow[3];
		$shopSessionId =  $newRow[4];
		$meetTime =  $newRow[5];
		$meetDay =  $newRow[6];
		$room = $newRow[8];
		$instructorId = $newRow[9];?>
		
		<tr>
			<td><input type='radio' name='selectWS' id='selectWS' value='<?php echo $shopSessionId;?>'></td>
			<td><?php echo $title;?></td>
			<td><?php echo $meetDay;?></td>
			<td><?php echo $meetTime;?></td>
			<td><?php echo $description;?></td>
		<?php
		$instructorInfo = mysql_query("select * from USERS where userId = $instructorId", $con);
		$getInstructor = mysql_fetch_row($instructorInfo);
		
		$instructFName = $getInstructor[1];
		$instructLName = $getInstructor[2];
		$instructorName = $instructFName . " " . $instructLName;
		?>
		
		<td><?php echo $instructorName; ?></td>
		
		<?php
		$roomInfo = mysql_query("select * from ROOM join BUILDING where ROOM.roomId = $room and ROOM.bldgId = BUILDING.bldgId",$con);
		$getRoom = mysql_fetch_row($roomInfo);
		
		$roomCap = $getRoom[1];
		$roomNum = $getRoom[2];
		$bldgName = $getRoom[5];
		?>
		
		<td><?php echo $bldgName;?></td>
		<td><?php echo $roomNum;?></td>
		<td><?php echo $roomCap;?></td>
		
		<?php
		$capInfo = mysql_query("select count(*) from WORKSHOP_SESSIONS as WS JOIN USER_WORKSHOP as UW ON WS.workshopSessionId=UW.workshopSessionId JOIN ROOM as R ON WS.roomId=R.roomId where R.roomId = $room", $con);
		$getCap = mysql_fetch_row($capInfo);
		
		$curEnroll = $getCap[0];
		?>
		<td><?php echo $curEnroll;?></td>		
		</tr>
		
		<?php
	}//end while ?>
	</tbody></table><input type='submit' value='Register for course'></form>
	
	<?php mysql_close($con);?>
</div> <!-- end .content -->
</div> <!-- end .content-container -->
<?php include('footer.php'); ?>
